package com.school.graduation.mine.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.school.graduation.R;
import com.school.graduation.bean.MineReleasedCallBack;
import com.school.graduation.mine.view.MineReleasedRecyclerViewHolder;

import java.util.ArrayList;
import java.util.List;

public class MineReleasedRecyclerAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<MineReleasedCallBack.GoodsBean> mGoodsList;

    public MineReleasedRecyclerAdapter(Context context) {
        mContext = context;
        mGoodsList = new ArrayList<>();
    }

    public void setGoodsList(List<MineReleasedCallBack.GoodsBean> list){
        mGoodsList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MineReleasedRecyclerViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_recommend_new, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MineReleasedRecyclerViewHolder mViewHolder = (MineReleasedRecyclerViewHolder) holder;
        TextView userName = mViewHolder.getView(R.id.good_item_name);
        TextView money = mViewHolder.getView(R.id.good_item_money);
        TextView detail = mViewHolder.getView(R.id.good_item_detail);
        TextView time = mViewHolder.getView(R.id.good_item_time);
        ImageView img = mViewHolder.getView(R.id.good_item_img);

        userName.setText(mGoodsList.get(position).getSellerName());
        money.setText(String.valueOf(mGoodsList.get(position).getPrice()));
        detail.setText(mGoodsList.get(position).getDetail());
        String timeText = mGoodsList.get(position).getMeta().getUpdateAt().substring(0,10)+" "+mGoodsList.get(position).getMeta().getCreateAt().substring(11,16);
        time.setText(timeText);
        Glide.with(mContext)
                .load(mGoodsList.get(position).getImg())
                .into(img);
    }

    @Override
    public int getItemCount() {
        return mGoodsList.size();
    }
}
